`
https://leetcode.cn/problems/preimage-size-of-factorial-zeroes-function/
`

/**
 * @param {number} k
 * @return {number}
 */
var preimageSizeFZF = function (k) {
  // 右端点相当于 k + 1 的左端点 - 1
  return searchLeft(k + 1) - searchLeft(k)
};

function searchLeft(k) {
  let left = -1, right = 5 * k + 1
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (trailingZeroes(mid) >= k) {
      right = mid
    } else {
      left = mid
    }
  }
  return right
}

// https://leetcode.cn/problems/factorial-trailing-zeroes/
var trailingZeroes = function (n) {
  let res = 0;
  let divisor = 5;
  while (divisor <= n) {
    res += Math.floor(n / divisor);
    divisor *= 5;
  }
  return res;
};